<template>
    <div>
        <h1>房号信息新增</h1>
        <hr>
        <table class="table">
            <tbody>
                <tr>
                    <td>房间号</td>
                    <td><input type="text" v-model="data.RNum"></td>
                </tr>
                <tr>
                    <td>房间名称</td>
                    <td><input type="text" v-model="data.RName"></td>
                </tr>
                <tr>
                    <td>房间类型</td>
                    <td>
                        <select v-model="data.TId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.TId">{{a.Name}}</option>
                        </select>
                    </td>
                </tr> 
                <tr>
                    <td>门店名称</td>
                    <td>
                        <select v-model="data.HId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang1" :value="a.HId">{{a.HName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房间状态</td>
                    <td><input type="checkbox" v-model="data.RState">选中为上架，不选中为下架</td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type="button" value="新增" @click="NAdd"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import RShow from '../RoomPrice/RShow.vue';
onMounted(()=>{
xia()
xia1()
})
const bang = ref([{
    "TId": 1,
    "Name": "毛坯房"
}])
const xia = ()=>{
    axios.get('https://localhost:7206/api/RoomNum/Xia1').then(res=>{
        bang.value = res.data
    })
}
const bang1 = ref([{
    "HId": 1,
    "HName": "轻轻饭店",
    "HProName": "青青",
    "HImg": "/img/2a097dd3-6727-4649-ba95-4a1aa915722e2.png",
    "MDate": "2025-06-16T07:57:40.365",
    "HApp": "山西临汾",
    "HState": false
}])
const xia1 = ()=>{
    axios.get('https://localhost:7206/api/RoomNum/Xia2').then(res=>{
        bang1.value = res.data
    })
}
const data = ref({
    "RId": 0,
  "RNum": "",
  "RName": "",
  "TId": 0,
  "HId": 0,
  "RState": true,
  "IsDelete": true
})
const router = useRouter()
const NAdd = ()=>{
    if(data.value.RNum==""){
        alert('房间号不能为空')
        return
    }
     if(data.value.RNum=="101"){
        alert('房间号只能出现一次')
        return
    }
    if(data.value.RNum=="102"){
        alert('房间号只能出现一次')
        return
    }
     if(data.value.RNum=="109"){
        alert('房间号只能出现一次')
        return
    }
    if(data.value.RName==""){
        alert("房间名称不能为空")
        return
    }


    axios.post('https://localhost:7206/api/RoomNum/NAdd',data.value).then(res=>{
        if(res.data>0){
            alert('新增成功');
            router.push({path:"/NShow"})
        }
        else{
            alert('新增失败');
        }
    })
}


</script>

<style scoped>

</style>